package spring.mvc.view;

import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.view.AbstractView;

/*
 View 클래스 구현
 1. extends AbstractView
 2. 메소드 Overriding
 	- renderMergedOutputModel(Map, request, response) : 응답할 내용을 구현(필수)
 	- getContentType() : String : 응답할 content의 타입을 문자열로 return(선택사항)
 */
public class DispatchView extends AbstractView{
	private String url;
	public void setUrl(String url){
		this.url = url;
	}
	@Override
	public String getContentType() {
		return "text/html";
	}

	@Override
	protected void renderMergedOutputModel(Map<String, Object> map,
			HttpServletRequest request, HttpServletResponse response) throws Exception {
		if(map!=null&&map.size()!=0){
			Set entries = map.entrySet();
			Iterator itr = entries.iterator();
			while(itr.hasNext()){
				Entry<String , Object> entry = (Entry)itr.next();
				request.setAttribute(entry.getKey(), entry.getValue());
			}
		}
		
		//요청 디스패치 방식으로 응답 처리
		RequestDispatcher rdp = request.getRequestDispatcher(url);
		rdp.forward(request, response);
		
	}
	
}



















